package com.nf.practice.lambdatest;

import org.apache.logging.log4j.message.StringFormattedMessage;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SumListMap {


    @Test
    public void test1() {
        List<Map<String, Object>> listMap = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        Map<String, Object> map2 = new HashMap<>();
        Map<String, Object> map3 = new HashMap<>();
        Map<String, Object> map4 = new HashMap<>();
        map1.put("id", "101");
        map2.put("id", "102");
        map3.put("id", "101");
        map4.put("id", "103");

        map1.put("total", 10);
        map2.put("total", 20);
        map3.put("total", 30);
        map4.put("total", 40);

        listMap.add(map1);
        listMap.add(map2);
        listMap.add(map3);
        listMap.add(map4);

    }

    private List<Map<String, Object>> sumByKey(List<Map<String, Object>> list, String key, String  addParams) {
        Map<String, List<Map<String, Object>>> grouped = new HashMap<>();
        for (Map<String, Object> map : list) {
            List<Map<String, Object>> maps = grouped.get(map.get(key));
            if (CollectionUtils.isEmpty(maps)) {
                maps = new ArrayList<>();
                grouped.put((String) map.get(key), maps);
            }
            maps.add(map);
        }

//        List<Map>

        return null;
    }
}
